package com.ljkj.blockpay.presenter;

import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;

import com.kongzue.baseokhttp.HttpRequest;
import com.kongzue.baseokhttp.listener.JsonResponseListener;
import com.kongzue.baseokhttp.util.JsonBean;
import com.kongzue.baseokhttp.util.JsonList;
import com.kongzue.baseokhttp.util.JsonMap;
import com.kongzue.baseokhttp.util.Parameter;
import com.ljkj.blockpay.basedata.BasePresenter;
import com.ljkj.blockpay.basedata.BasePresenterImpl;
import com.ljkj.blockpay.basedata.BaseView;
import com.ljkj.blockpay.model.RechargeModel;
import com.ljkj.blockpay.network.ApiToCConfig;
import com.ljkj.blockpay.presenter.inter.WithdrawInter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yp on 2022/3/9
 */
public class WithdrawDetailPresenter extends BasePresenterImpl<WithdrawInter.WithdrawInterView> implements WithdrawInter.WithdrawInterPresenterView, BasePresenter {


    public WithdrawDetailPresenter(@NonNull Context context, @NonNull WithdrawInter.WithdrawInterView view) {
        super(context, view);
    }

    @Override
    public void getNetAccuracy() {
        HttpRequest.GET(getContext(), ApiToCConfig.URL_TRADE_NETWORK_ACCURACY, new Parameter().add("orderType", "3"), new JsonResponseListener() {
            @Override
            public void onResponse(JsonMap main, Exception error) {
                if (main.getInt("code") == 0){
                    JsonList jsonList = main.getList("data");
                    List<RechargeModel> list = new ArrayList<>();
                    for (int i = 0; i < jsonList.size(); i++) {
                        list.add(JsonBean.getBean(jsonList.getJsonMap(i), RechargeModel.class));
                    }
                    getView().showNetAccuracy(list);
                    Log.d("zdl","==onSafeSuccess==="+list.size());
                }else{
                }
            }
        });
    }

    /**
     * 添加地址
     */
    @Override
    public void addAddress() {
        HttpRequest.POST(getContext(), ApiToCConfig.USER_ADDRESS_ADD, new Parameter(), new JsonResponseListener() {
            @Override
            public void onResponse(JsonMap main, Exception error) {
                if (main.getInt("code") == 0){
                    JsonMap jsonMap = new JsonMap("data");
                    getView().addAddressSuccess(jsonMap);
                }
            }
        });
    }


    /**
     * 修改地址
     */
    @Override
    public void updateAdress() {
        HttpRequest.POST(getContext(), ApiToCConfig.USER_UPDATE, new Parameter(), new JsonResponseListener() {
            @Override
            public void onResponse(JsonMap main, Exception error) {
                if (main.getInt("code") == 0){

                } else {

                }
            }
        });
    }

}
